package com.vimhe.easyimport.validate;

import com.vimhe.easyimport.config.bean.CellConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * 数据验证器链
 *
 * @author Vimhe
 */
public class DataValidatorChain implements DataValidator {

    /**
     * 数据验证器列表
     */
    private List<DataValidator> dataValidators = new ArrayList<>();

    /**
     * 添加数据过滤器
     *
     * @param dataValidator 数据验证器
     * @return 数据验证器链
     */
    public DataValidatorChain addValidator(DataValidator dataValidator) {
        dataValidators.add(dataValidator);
        return this;
    }

    @Override
    public List<ErrorMessage> validate(String fileName, int sheetIndex, int rowIndex, String cellIndex, CellConfig cellConfig, Object cellValue) {
        List<ErrorMessage> errorMessages = new ArrayList<>();

        for (DataValidator dataValidator : dataValidators) {
            errorMessages = dataValidator.validate(fileName, sheetIndex, rowIndex, cellIndex, cellConfig, cellValue);
        }

        return errorMessages;
    }

}
